package com.dream.testtubebaby.adapter;

import java.util.List;

import android.content.Context;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.view.View;

import com.dream.testtubebaby.R;
import com.dream.testtubebaby.data.chat.ChatListItem;
import com.dream.testtubebaby.utils.ViewHolder;

public class MyChatListAdapter extends CommonAdapter<ChatListItem> {

	public MyChatListAdapter(Context context, List<ChatListItem> mDatas,
			int itemLayoutId) {
		super(context, mDatas, itemLayoutId);
	}

	public void setDatas(List<ChatListItem> mDatas) {
		this.mDatas.clear();
		this.mDatas.addAll(mDatas);
	}

	public void addAll(List<ChatListItem> mDatas) {
		this.mDatas.addAll(mDatas);
	}
	
	@Override
	public void convert(final ViewHolder helper, final ChatListItem item) {
		helper.setText(R.id.chat_title_tv, item.getTitle());
		CharSequence time_string = DateUtils.getRelativeTimeSpanString(
				item.getTime(), System.currentTimeMillis(),
				DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE);

		helper.setText(R.id.chat_time_tv, time_string.toString());
		if(TextUtils.isEmpty(item.getContent())){
			helper.getView(R.id.chat_content_tv).setVisibility(View.GONE);
		}else{
			helper.getView(R.id.chat_content_tv).setVisibility(View.VISIBLE);
			helper.setText(R.id.chat_content_tv, item.getContent());
		}
	}
}
